#ifndef EVENTLABEL
#define EVENTLABEL

#include <QLabel>
#include <QMouseEvent>

class EventLabel : public QLabel
{
//    Q_OBJECT
public:
    EventLabel();
    virtual ~EventLabel() {}
protected:
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
};

EventLabel::EventLabel()
    :QLabel()
{
    setWindowTitle("MouseEvent Demo");
    resize(320, 200);
    setMouseTracking(true);   //设置自动追踪鼠标
}

void EventLabel::mouseMoveEvent(QMouseEvent *event)
{
    this->setText(QString("<center><h1>Move: (%1, %2)</h1></center>").arg(QString::number(event->x()), QString::number(event->y())));
}

void EventLabel::mousePressEvent(QMouseEvent *event)
{
    this->setText(QString("<center><h1>Press: (%1, %2)</h1></center>").arg(QString::number(event->x()), QString::number(event->y())));
}

void EventLabel::mouseReleaseEvent(QMouseEvent *event)
{
    this->setText(QString("<center><h1>Release: (%1, %2)</h1></center>").arg(QString::number(event->x()), QString::number(event->y())));
}

void EventLabel::keyPressEvent(QKeyEvent *event)
{
    this->setText(QString("<center><h1>Key Press: (%1, %2)</h1></center>").arg(QString::number(event->type()), QString::number(event->key())));
}

void EventLabel::keyReleaseEvent(QKeyEvent *event)
{
    this->setText(QString("<center><h1>Key release: (%1, %2)</h1></center>").arg(QString::number(event->type()), QString::number(event->key())));
}


#endif // EVENTLABEL

